import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;


public class Bullet {
    private BufferedImage bullimag;
    private BufferedImage bullimag2;
    private double initX;
    private double initY;
    private Point position;
    private boolean isEnemy;
    private double xDest;
    private double yDest;
    private double yInc;
    private double xInc;
    
    
    public Bullet(Point position, Point destination, boolean isEnemy){
        try {
        	bullimag  = ImageIO.read(new File("bullet.png"));
        	bullimag2 = ImageIO.read(new File("bulletEnemy.png"));
        } catch (IOException e) {
        	e.printStackTrace();
        }
        initX = position.getX();
        initY = position.getY();
        this.position = position;
        this.isEnemy = isEnemy;
        xDest = (destination.getX()-position.getX());
        yDest = (destination.getY()-position.getY());
        double division = Math.sqrt((xDest*xDest)+(yDest*yDest));
        division =  division/2;
        xDest = (destination.getX()-position.getX())/division;
        yDest = (destination.getY()-position.getY())/division;
        yInc=yDest;
        xInc=xDest;
    }
    
    public BufferedImage getImage(){
    	if(isEnemy){
    		return bullimag2;
    	}
            return bullimag;
    }
    
    public void move(){
        yDest+=yInc;
        xDest+=xInc;
        position.setLocation(initX+xDest, initY+yDest);
    }
    
    public int getX(){
    	return (int) position.getX();
    }
    
    public int getY(){
    	return (int) position.getY();
    }
    
    public Point middle(){
    	return new Point(position.x+6, position.y+6);
    }
    public boolean isEnemys(){
    	return isEnemy;
    }
    
    public Point getPoint(){
    	return position;
    }        
}
